﻿<?php

/**
 * This is the model class for table "sport".
 *
 * The followings are the available columns in table 'sport':
 * @property string $id
 * @property string $name
 * @property string $gender
 * @property integer $state
 * @property double $imc
 * @property integer $interests
 * @property integer $min_age
 * @property integer $max_age
 * @property integer $type
 */
class Sport extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Sport the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'sport';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, gender, type', 'required'),
			array('state, interests, min_age, max_age, type', 'numerical', 'integerOnly'=>true),
			array('imc', 'numerical'),
			array('name', 'length', 'max'=>80),
			array('gender', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, gender, state, imc, interests, min_age, max_age, type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'imc'=>array(self::BELONGS_TO, 'Imc', 'imc'),
			'interests'=>array(self::BELONGS_TO, 'Interest', 'id'),
			'type'=>array(self::BELONGS_TO, 'type', 'id'),
			'state'=>array(self::BELONGS_TO, 'state', 'id')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Nombre',
			'gender' => 'Sexo',
			'state' => 'Estado físico',
			'imc' => 'IMC',
			'interests' => 'Intereses',
			'min_age' => 'Edad mínima',
			'max_age' => 'Edad máxima',
			'type' => 'Tipo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('state',$this->state);
		$criteria->compare('imc',$this->imc);
		$criteria->compare('interests',$this->interests);
		$criteria->compare('min_age',$this->min_age);
		$criteria->compare('max_age',$this->max_age);
		$criteria->compare('type',$this->type);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}